/**
 * 分类模型
 * @module models/Category
 */

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

/**
 * 分类模型定义
 * @typedef {Object} Category
 * @property {string} name - 分类名称
 * @property {string} description - 分类描述
 * @property {number} postCount - 文章数量
 */
const Category = sequelize.define('Category', {
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    validate: {
      notEmpty: true,
      len: [2, 50]
    }
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  postCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  }
});

module.exports = Category; 